var hyischoiced=[];//已经选择的行业
var xqischoiced=[];//已经选择的兴趣
var alwaysnews=[];//已经选择的常看的新闻
var xqchoicenum=0;
var choicenum=0;//
var alwayschoicenum=0;
var hychoicenum=0;//行业
var pw;//密码
var sex=0;
var userAva; //保存头像名称
var score="";
var allmychoicecityclick=0;//全局变量 点击的页面
if(!location.href=="http://www.tiantianqiche.cn/mysetpage.html"){location.href="http://www.tiantianqiche.cn/mysetpage.html"}
//设置页返回
$("#mainsetpagegoback").click(function(){
    location.href="setpage.html"
});
//我常看的新闻返回
$("#alwaysseepagegoback").click(function(){
    $("#alwayschoicepage").css("display","none");
    $("#page_wrapper").css("display","block");
});
//我的行业返回
$("#myjobpagegoback").click(function(){
    $("#choicepage").css("display","none");
    $("#page_wrapper").css("display","block");
});
//我的兴趣返回
$("#hobbypagegoback").click(function(){
    $("#xqchoicepage").css("display","none");
    $("#page_wrapper").css("display","block");
});
//我的城市返回
//....
//我的学历返回
$("#edupagegoback").click(function(){
    $("#edchoicepage").css("display","none");
    $("#page_wrapper").css("display","block");
});

var he=window.screen.height-104;
$("#allcitypage").css("height",he);
//=========================删除已选择行业兴趣新闻===================================================================
function hydeletaspan(e){
    $(e).remove();
    e.className="tc_inner";
    $("#hychoicedbox span#"+e.id).remove();
    hychoicenum--;
}
function xqdeletaspan(e){
    $(e).remove();
    e.className="tc_inner";
    $("#xqchoicedbox span#"+e.id).remove();
    xqchoicenum--;
}
function aldeletaspan(e){
    $(e).remove();
    e.className="tc_inner";
    $("#alwayschoicedbox span#"+e.id).remove();
    alwayschoicenum--;
}
var xquserdata;//已经选择的兴趣
var hyuserdata;//已经选择的行业
var xwuserdata;//已经选择的新闻
$().ready(function(){
    var edokbtnimg2=document.getElementsByClassName("edokbtnimg2");//学历选中按钮图片2 没有选择
    var edokbtnimg1=document.getElementsByClassName("edokbtnimg1");//学历选中按钮图片1 选中
    //发送请求获取用户已有的信息
    $.ajax({
        type: "post",
        datatype: "json",
        url: userurl,
        data:{"userId":id},
        success:function(data){
            console.log(data);
            userdata=data;
            pw=data.Data.pw;
            score=data.Data.score;
            $("#nick_name").val(data.Data.nick);
            sex=data.Data.sex;
            if(sex===1){
                $("#sexbox1").css("display","block");
                $("#sexbox2").css("display","none");
            }else if(sex===0){
                $("#sexbox1").css("display","none");
                $("#sexbox2").css("display","block");
            }
            //学历
            switch (data.Data.education){
                case "初中及以下":
                    console.log("初中级以下执行比较了");
                    edokbtnimg2[0].style.display="none";
                    edokbtnimg1[0].style.display="block";
                    break;
                case "高中":
                    console.log("初中级以下执行比较了");
                    edokbtnimg2[1].style.display="none";
                    edokbtnimg1[1].style.display="block";
                    break;
                case "大学":
                    console.log("初中级以下执行比较了");
                    edokbtnimg2[2].style.display="none";
                    edokbtnimg1[2].style.display="block";
                    break;
                case "硕士及以上":
                    console.log("初中级以下执行比较了");
                    edokbtnimg2[3].style.display="none";
                    edokbtnimg1[3].style.display="block";
                    break;
            }
            $(".eduwords").html(data.Data.education);
            //$("#education").val(data.Data.education);
            if(data.Data.visitedcity){
                var b=data.Data.visitedcity.match(/([\u4e00-\u9fa5]+)/g);
                for(var i5=0;i5<b.length;i5++){
                    $(".ctywords").append("<span>"+b[i5]+"</span>");
                }
            }
            //$("#choicedbox").append("<span id='"+event.target.id+"' onclick='hydeletaspan(this)'>"+event.target.innerHTML+"<a>×</a></span>");
            //行业兴趣新闻------------------------------

            //if(data.Data.jobs.length>3){
            //    hyuserdata=data.Data.jobs;
            //    hychoicenum=3;
            //    for(var i1=0;i1<3;i1++){
            //        $(".hangyewords").append("<span>"+data.Data.jobs[i1].typename+"</span>");
            //        hyischoiced.push({"id":data.Data.jobs[i1].id,"typename":data.Data.jobs[i1].typename});
            //        $("#choicedbox").append("<span id='"+data.Data.jobs[i1].id+"' onclick='hydeletaspan(this)'>"+data.Data.jobs[i1].typename+"<a>×</a></span>");
            //    }
            //}else if(data.Data.jobs.length>0&&data.Data.jobs.length<=3){
            //    hyuserdata=data.Data.jobs;
            //    hychoicenum=data.Data.jobs.length;
            //    for(var i2=0;i2<data.Data.jobs.length;i2++){
            //        $(".hangyewords").append("<span>"+data.Data.jobs[i2].typename+"</span>");
            //        hyischoiced.push({"id":data.Data.jobs[i2].id,"typename":data.Data.jobs[i2].typename});
            //        $("#choicedbox").append("<span id='"+data.Data.jobs[i2].id+"' onclick='hydeletaspan(this)'>"+data.Data.jobs[i2].typename+"<a>×</a></span>");
            //    }
            //}
            //if(data.Data.hobbys&&data.Data.hobbys.length>3){
            //    xquserdata=data.Data.hobbys;
            //    xqchoicenum=3;
            //    for(var i3=0;i3<3;i3++){
            //        $(".xingquwords").append("<span>"+data.Data.hobbys[i3].typename+"</span>");
            //        xqischoiced.push({"id":data.Data.hobbys[i3].id,"typename":data.Data.hobbys[i3].typename});
            //        $("#xqchoicedbox").append("<span id='"+data.Data.hobbys[i3].id+"' onclick='xqdeletaspan(this)'>"+data.Data.hobbys[i3].typename+"<a>×</a></span>");
            //    }
            //}else if(data.Data.hobbys.length>0&&data.Data.hobbys.length<=3){
            //    xquserdata=data.Data.hobbys;
            //    xqchoicenum=data.Data.hobbys.length;
            //    for(var i=0;i<data.Data.hobbys.length;i++){
            //        $(".xingquwords").append("<span>"+data.Data.hobbys[i].typename+"</span>");
            //        xqischoiced.push({"id":data.Data.hobbys[i].id,"typename":data.Data.hobbys[i].typename});
            //        $("#xqchoicedbox").append("<span id='"+data.Data.hobbys[i].id+"' onclick='xqdeletaspan(this)'>"+data.Data.hobbys[i].typename+"<a>×</a></span>");
            //    }
            //}
            //if(data.Data.news&&data.Data.news.length>3){
            //    xwuserdata=data.Data.news;
            //    alwayschoicenum=3;
            //    for(var i4=0;i4<3;i4++){
            //        $(".alwayswords").append("<span>"+data.Data.news[i4].typename+"</span>");
            //        alwaysnews.push({"id":data.Data.news[i4].id,"typename":data.Data.news[i4].typename});
            //        $("#alwayschoicedbox").append("<span id='"+data.Data.news[i4].id+"' onclick='aldeletaspan(this)'>"+data.Data.news[i4].typename+"<a>×</a></span>");
            //    }
            //}else if(data.Data.news.length>0&&data.Data.news.length<=3){
            //    xwuserdata=data.Data.news;
            //    alwayschoicenum=data.Data.news.length;
            //    for(var i=0;i<data.Data.news.length;i++){
            //        $(".alwayswords").append("<span>"+data.Data.news[i].typename+"</span>");
            //        alwaysnews.push({"id":data.Data.news[i].id,"typename":data.Data.news[i].typename});
            //        $("#alwayschoicedbox").append("<span id='"+data.Data.news[i].id+"' onclick='aldeletaspan(this)'>"+data.Data.news[i].typename+"<a>×</a></span>");
            //    }
            //}

            //$("#cities").val(data.Data.visitedcity);
            $("#mylabel").val(data.Data.cover);
            $("#personalword").val(data.Data.sign);
            $(".myctywords").append("<span>"+data.Data.city+"</span>");
            if(data.Data.userAva){
                userAva=data.Data.userAva;

                img_area.innerHTML = '<img src="'+imgurl+data.Data.userAva+'" alt=""/>'
            }else if(!data.Data.userAva){
                img_area.style.background="url(img/loseimg.png) no-repeact";
            }
        }
    });
    //最高学历
    document.getElementsByClassName("eudcationbtn")[0].onclick=function(){
        document.getElementById("edchoicepage").style.display="block";
        document.getElementById("page_wrapper").style.display="none";
    };
    //我的城市返回
    $("#citypagegoback").click(function(){
        mychoicecityclick=0;
        allmychoicecityclick=0;
        $("#ctchoicepage").css("display","none");
        $("#page_wrapper").css("display","block");
    });
    var edlist=document.getElementsByClassName("edlist");//学历列表
    var eduword="";
    for(var e=0;e<edlist.length;e++){
        edlist[e].index=e;
        edlist[e].onclick=function(event){
            if(edokbtnimg2[this.index].style.display==="none"){
                edokbtnimg2[this.index].style.display="block";
                edokbtnimg1[this.index].style.display="none";
                eduword="";
                $(".eduwords").html("");
                document.getElementById("edchoicepage").style.display="none";
                document.getElementById("page_wrapper").style.display="block";
            }else if(edokbtnimg2[this.index].style.display==="block"){
                for(var i=0;i<edlist.length;i++){
                    edokbtnimg2[i].style.display="block";
                    edokbtnimg1[i].style.display="none";
                    eduword="";
                }
                edokbtnimg2[this.index].style.display="none";
                edokbtnimg1[this.index].style.display="block";
                eduword=edlist[this.index].innerHTML.match(/([\u4E00-\u9FA5]+)/)[0];
                $(".eduwords").html(eduword);
                document.getElementById("edchoicepage").style.display="none";
                document.getElementById("page_wrapper").style.display="block";
            }
        }
    }
    document.getElementById("edfinish").onclick=function(){
        document.getElementById("edchoicepage").style.display="none";
        document.getElementById("page_wrapper").style.display="block";
    };
    //所在城市
    var mychoicecityclick=0;//当前点击的那个页面
    //所在城市
    $(".mychoicecitybtn").click(function(){
        $(".ctokbtnimg1").css("display","none");
        $(".ctokbtnimg2").css("display","none");
        $("#ctfinish").css("display","none");
        $("#page_wrapper").css("display","none");
        $("#ctchoicepage").css("display","block");
        $("#choicecitybox").css("display","none");
        //document.getElementById("ctchoicepage").style.marginTop="98px";
        mychoicecityclick=1;
        allmychoicecityclick=1;
    });
    var choicenum=0;//城市已经选择的个数
    //待过的城市
    $(".choicecitybtn").click(function(){
        $("#choicecitybox span").remove();//城市列表中已经选择的城市
        $(".ctokbtnimg1").css("display","none");
        $(".ctokbtnimg2").css("display","block");
        $("#ctfinish").css("display","block");
        if(document.querySelectorAll(".kindword.ctywords span")){
            var mycityspan=document.querySelectorAll(".kindword.ctywords span");
            choicenum=mycityspan.length;

            for(var r= 0,l=mycityspan.length;r<l;r++){
                var spanid=pinyin.getFullChars(mycityspan[r].innerHTML).toLowerCase();
                $("#choicecitybox").append("<span id='s"+spanid+"'>"+mycityspan[r].innerHTML+"</span>");
                $("#"+spanid+" .ctokbtnimg2").css("display","none");
                $("#"+spanid+" .ctokbtnimg1").css("display","block");
            }
        }
        $("#allcitypage").css("height",he-40);
        $("#ctchoicepage").css("display","block");
        $("#page_wrapper").css("display","none");
        $("#choicecitybox").css("display","block");
    });
    var hasharr={};//保存第一个首字母的位置
    //加载城市列表
    for(var c1=0;c1<citylist.length;c1++){
        var pinyinid=pinyin.getFullChars(citylist[c1].name).toLowerCase();
        $("#"+citylist[c1].pinyin[0]+" .box").append("<span class='tc_inner' id='"+pinyinid+"'>"+citylist[c1].name+"<div class='rt ctokbtn'> <img src='img/hook-no.png' class='ctokbtnimg2' style='display: block'/> <img src='img/hook01.png' class='ctokbtnimg1' style='display: none'/> </div> </span> <div class='tc_stroke'></div>");
    }
    hasharr.A=0; //hash。A不是0 更改
    for(var key in hasharr){
        $("div.listtitle").eq(hasharr[key]).css("display","block");
    }
    //var choicenum=0;//城市已经选择的个数
    $("li.ctlist span.tc_inner").click(function(e){//列表点击

        var word="";
        var s1;
        var spid="";
        if(e.target.nodeName==="IMG"){

            word=e.target.parentNode.parentNode.innerHTML.match(/[\u4e00-\u9fa5]+/)[0];
            s1=e.target.parentNode.parentNode.getElementsByTagName("img");
            spid="s"+e.target.parentNode.parentNode.id;
        }else{
            word=e.target.innerHTML.match(/[\u4e00-\u9fa5]+/)[0];
            s1=e.target.getElementsByTagName("img");
            spid="s"+e.target.id;
        }

        if(mychoicecityclick===1){
            $(".myctywords span").remove();//所在城市（编辑主页展示）
            $(".myctywords").append("<span id='s"+spid+"'>"+word+"</span>");
            $("#page_wrapper").css("display","block");
            $("#ctchoicepage").css("display","none");
            $(".ctokbtnimg2").css("display","block");
            $("#ctfinish").css("display","block");
            $("#choicecitybox").css("display","block");
            mychoicecityclick=0;
            allmychoicecityclick=0;
        }else{
            if(s1[0].style.display==="block"){
                if(choicenum<3){
                    s1[0].style.display="none";
                    s1[1].style.display="block";
                    choicenum++;
                    $("#choicecitybox").append("<span id='"+spid+"'>"+word+"</span>")
                }
            }else if(s1[0].style.display==="none"){
                s1[0].style.display="block";
                s1[1].style.display="none";
                var addspan=document.getElementsByTagName("span");
                for(var i=0;i<addspan.length;i++){
                    addspan[i].index=i;

                    if(addspan[i].innerHTML.match(/[\u4e00-\u9fa5]+/)[0]===word){
                        var spanname="span#"+spid;

                        $("span#"+spid).remove();
                        choicenum--;
                        break;
                    }else{
                        console.log("没有找到span")
                    }
                }
            }
        }
    });
    var englishbtn=document.querySelectorAll(".rightnav div");//导航条跳转
    var tonum=0;
    for(var en=0;en<englishbtn.length;en++){
        englishbtn[en].onclick=function(e){
            location.href="#"+e.target.innerHTML;
            //$(document).scrollTop();
            if(mychoicecityclick===1){
                $(document).scrollTop($(document).scrollTop()-104);
            }else{
                $(document).scrollTop($(document).scrollTop()-142);
            }
        }
    }
    //搜索跳转
    $("#csearchbtn").click(function(){
        var word=$("#csearchinput").val();
        var allcitylist=document.getElementsByClassName("tc_inner");
        for(var i=0;i<allcitylist.length;i++){
            var listinner=allcitylist[i].innerHTML.match(/[\u4e00-\u9fa5]+/)[0];
            if(listinner===word){

                var pinyinid=pinyin.getFullChars(word).toLowerCase();

                location.href="#"+pinyinid;
                if(mychoicecityclick===1){

                    $(document).scrollTop($(document).scrollTop()-104);
                }else{

                    $(document).scrollTop($(document).scrollTop()-142);
                }
                break;
            }
        }
    });
    $("#ctfinish").click(function(){ //关闭城市列表
        choicenum=0;
        $("#ctchoicepage").css("display","none");
        $("#page_wrapper").css("display","block");
        var showspan=document.querySelectorAll("#choicecitybox span");
        if(showspan&&showspan.length>0){
            $(".ctywords span").remove();//待过的城市（编辑主页展示）
            for(var i=0;i<showspan.length;i++){
                $(".ctywords").append("<span>"+showspan[i].innerHTML+"</span>");
            }
        }
    });
    //获取行业列表------------------------------------------------------------------------------------------------------
    $(".hangyelistbtn").click(function(){
        $("#choicepage").css("display","block");
        $("#page_wrapper").css("display","none");
        $.ajax({
            type:"get",
            url:joblisturl,
            success:function(data){
                var tim=0;
                for(var i=0;i<data.Data.length;i++){
                    tim++;
                    $("#ts_cells").append("<li class='Cell'><span class='tc_inner' id='"+data.Data[i].id+"'>"+data.Data[i].typename+"</span><div class='tc_stroke'></div></li>");
                    if(tim==data.Data.length){
                        if(hyuserdata&&hyuserdata.length>0){
                            if(hyuserdata.length>=3){
                                for(var r=0;r<3;r++){
                                    $("#ts_cells #"+hyuserdata[r].id).attr("class","tc_inner isclicked");
                                }
                            }else{
                                for(var r1=0;r1<hyuserdata.length;r1++){
                                    $("#ts_cells #"+hyuserdata[r1].id).attr("class","tc_inner isclicked");
                                }
                            }
                        }
                    }
                }
            }
        });
    });
    //行业列表项添加点击事件
    $(".bigbox1").delegate("#choicepage .tc_inner","click",function(event){
        if(event.target.className=="tc_inner"){
            choicenum++;
            event.target.className+=" isclicked";

            ///////////////////////////////
            if(!document.querySelectorAll("#choicedbox span")[0]||document.querySelectorAll("#choicedbox span").length<3){
                $("#choicedbox").append("<span id='"+event.target.id+"' onclick='hydeletaspan(this)'>"+event.target.innerHTML+"<a>×</a></span>");
            }else if(document.querySelectorAll("#choicedbox span").length==3){
                $("#choicedbox span:first-child").remove();
                $("#choicedbox").append("<span id='"+event.target.id+"' onclick='hydeletaspan(this)'>"+event.target.innerHTML+"<a>×</a></span>");
                choicenum=3;
            }
            ///////////////////////////////
        }else if(event.target.className=="tc_inner isclicked"){
            //alert("已经选择");

            event.target.className="tc_inner";
            $("#choicedbox span#"+event.target.id).remove();
            choicenum--;

        }
    });
    $("#finish").click(function(){
        hyischoiced=[];
        for(var r=0;r< $("#choicedbox span").length;r++){
            hyischoiced.push({"id":$("#choicedbox span")[r].id,"typename":$("#choicedbox span")[r].innerHTML.match(/[\u4e00-\u9fa5|a-z|A-Z]+/)[0]});

        };
        $("#choicepage").css("display","none");
        $("#page_wrapper").css("display","block");
        $(".hangyewords span").remove();
        for(var r2=0;r2<hyischoiced.length;r2++){
            $(".hangyewords").append("<span>"+hyischoiced[r2].typename+"</span>");
            if($(".hangyewords span").length>3){
                $(".hangyewords span:first").remove();
            }
        }
    });
    //获取兴趣列表=========================================
    $(".xingqulistbtn").click(function(){
        $("#xqchoicepage").css("display","block");
        $("#page_wrapper").css("display","none");
        $.ajax({
            type:"get",
            url:hobbylisturl,
            success:function(data){
                var tim=0;
                for(var i=0;i<data.Data.length;i++){
                    tim++;
                    $("#xqts_cells").append("<li class='Cell'><span class='tc_inner' id='"+data.Data[i].id+"'>"+data.Data[i].typename+"</span><div class='tc_stroke'></div></li>");
                    //已经选择的 改CLASS
                    if(tim==data.Data.length){
                        if(xquserdata&&xquserdata.length>0){
                            if(xquserdata.length>=3){
                                for(var r=0;r<3;r++){
                                    $("#xqts_cells #"+xquserdata[r].id).attr("class","tc_inner isclicked");
                                }
                            }else{
                                for(var r1=0;r1<xquserdata.length;r1++){
                                    $("#xqts_cells #"+xquserdata[r1].id).attr("class","tc_inner isclicked");
                                }
                            }
                        }
                    }
                }
            }
        });
    });
    //兴趣列表项添加点击事件
    $(".bigbox2").delegate("#xqchoicepage .tc_inner","click",function(event){
        if(event.target.className=="tc_inner"){
            //xqchoicenum++;
            event.target.className+=" isclicked";
            if(!document.querySelectorAll("#xqchoicedbox span")[0]||document.querySelectorAll("#xqchoicedbox span").length<3){
                $("#xqchoicedbox").append("<span id='"+event.target.id+"' onclick='xqdeletaspan(this)'>"+event.target.innerHTML+"<a>×</a></span>");
            }else if(document.querySelectorAll("#xqchoicedbox span").length==3){
                $("#xqchoicedbox span:first-child").remove();
                $("#xqchoicedbox").append("<span id='"+event.target.id+"' onclick='xqdeletaspan(this)'>"+event.target.innerHTML+"<a>×</a></span>");
                xqchoicenum=3;
            }
        }else if(event.target.className=="tc_inner isclicked"){
            event.target.className="tc_inner";
            $("#xqchoicedbox span#"+event.target.id).remove();
            xqchoicenum--;
        }
    });
    $("#xqfinish").click(function(){
        xqischoiced=[];
        for(var i=0;i< $("#xqchoicedbox span").length;i++){
            xqischoiced.push({"id":$("#xqchoicedbox span")[i].id,"typename":$("#xqchoicedbox span")[i].innerHTML.match(/[\u4e00-\u9fa5|a-z|A-Z]+/)[0]});
        };
        $("#xqchoicepage").css("display","none");
        $("#page_wrapper").css("display","block");
        $(".xingquwords span").remove();
        for(var r=0;r<xqischoiced.length;r++){
            $(".xingquwords").append("<span>"+xqischoiced[r].typename+"</span>");
            if($(".xingquwords>span").length>3){
                $(".xingquwords>span:first-child").remove();
            }
        }
    });
    //我常看的新闻==========================================
    $(".alwaysseelistbtn").click(function(){
        $("#alwayschoicepage").css("display","block");
        $("#page_wrapper").css("display","none");
        $.ajax({
            type:"get",
            url:zonghenewsurl,
            success:function(data){
                var tim=0;
                for(var i=0;i<data.Data.length;i++){
                    tim++;
                    $("#alwaysts_cells").append("<li class='Cell'><span class='tc_inner' id='"+data.Data[i].id+"'>"+data.Data[i].typename+"</span><div class='tc_stroke'></div></li>");
                    //已经选择的 改CLASS
                    if(tim==data.Data.length){
                        if(xwuserdata&&xwuserdata.length>0){
                            if(xwuserdata.length>=3){
                                for(var r=0;r<3;r++){
                                    $("#alwaysts_cells #"+xwuserdata[r].id).attr("class","tc_inner isclicked");
                                }
                            }else{
                                for(var r1=0;r1<xwuserdata.length;r1++){
                                    $("#alwaysts_cells #"+xwuserdata[r1].id).attr("class","tc_inner isclicked");
                                }
                            }
                        }
                    }
                }
            }
        });
    });
    //常看新闻添加点击事件
    $(".bigbox1").delegate("#alwayschoicepage .tc_inner","click",function(event){
        if(event.target.className=="tc_inner"){
            //alwayschoicenum++;
            event.target.className+=" isclicked";
            if(!document.querySelectorAll("#alwayschoicedbox span")[0]||document.querySelectorAll("#alwayschoicedbox span").length<3){

                $("#alwayschoicedbox").append("<span id='"+event.target.id+"' onclick='aldeletaspan(this)'>"+event.target.innerHTML+"<a>×</a></span>");

            }else if(document.querySelectorAll("#alwayschoicedbox span").length==3){
                $("#alwayschoicedbox span:first-child").remove();
                $("#alwayschoicedbox").append("<span id='"+event.target.id+"' onclick='aldeletaspan(this)'>"+event.target.innerHTML+"<a>×</a></span>");
                alwayschoicenum=3;
            }
        }else if(event.target.className=="tc_inner isclicked"){
            event.target.className="tc_inner";
            $("#alwayschoicedbox span#"+event.target.id).remove();
            alwayschoicenum--;
        }
    });
    $("#alwaysfinish").click(function(){
        alwaysnews=[];
        for(var r=0;r< $("#alwayschoicedbox span").length;r++){
            alwaysnews.push({"id":$("#alwayschoicedbox span")[r].id,"typename":$("#alwayschoicedbox span")[r].innerHTML.match(/[\u4e00-\u9fa5|a-z|A-Z]+/)[0]});

        };
        $("#alwayschoicepage").css("display","none");
        $("#page_wrapper").css("display","block");
        $(".alwayswords span").remove();
        for(var r2=0;r2<alwaysnews.length;r2++){
            $(".alwayswords").append("<span>"+alwaysnews[r2].typename+"</span>");
            if($(".alwayswords span").length>3){
                $(".alwayswords span:first").remove();
            }
        }
    });
    //选择性别
    $("#choicesex").click(function(){
        if($("#sexbox1").css("display")=="block"){
            $("#sexbox1").css("display","none");
            $("#sexbox2").css("display","block");
            sex=0;
        }else if($("#sexbox1").css("display")=="none"){
            $("#sexbox1").css("display","block");
            $("#sexbox2").css("display","none");
            sex=1;
        }
    });
    //上传图片
    var img_area = document.getElementById("upload-img");
    //=======图片压缩上传===============================================================================================
    $(document).ready(function(e) {
        $('#touxiangbtn').localResizeIMG({
            width: 300,
            quality: 1,
            success: function (result) {
                //var submitData={
                //    base64_string:result.base64
                //};
                var submitData=result.base64;
                $.ajax({
                    type: "POST",
                    url: "http://42.62.66.198:9001/api/PuluQuestion/UploadImg",
                    data: { "base64":submitData, "type": ".jpg","flag":1 },
                    dataType:"json",
                    success: function(data){
                        console.log("进行图片的压缩上传");
                        console.log(data.Data);
                        userAva=data.Data;
                        img_area.innerHTML = '<img src="'+imgurl+data.Data+'" alt=""/>';
                    }
                });
            }
        });
    });
    //向服务器提交数据
    $("#savechange").click(function(){
        var nick=$("#nick_name").val(); //昵称
        if(!nick||nick.match(/^\s+$/g)){
            alert("昵称不能为空");
        }else{
            if(nick.length>7){
                alert("昵称最长7个字符");
            }else{
                var education=$(".eduwords").html();  //教育
                //var visitedcity=$("#visitedcity").val();  //待过的城市
                var cities="";
                if(document.querySelectorAll(".ctywords span").length>0){
                    var showspan=document.querySelectorAll(".ctywords span");
                    for(var r=0;r<showspan.length;r++){
                        cities+=" "+showspan[r].innerHTML;
                    }
                }
                var city="";
                if(document.querySelectorAll(".myctywords span").length>0){
                    var showmyspan=document.querySelector(".myctywords span");
                    if(document.querySelector(".myctywords span").innerHTML){
                        city=document.querySelector(".myctywords span").innerHTML;
                    }
                }
                var sign=$("#personalword").val();  //个性签名
                var hobby="";//兴趣ID
                var job="";//行业ID
                var news="";//新闻ID
                var cover=$("#mylabel").val();//自定义标签
                //行业兴趣反了
                for(var i=0;i<hyischoiced.length;i++){
                    job+=hyischoiced[i].id+",";
                };
                for(var r=0;r<xqischoiced.length;r++){
                    hobby+=xqischoiced[r].id+",";
                };
                for(var t=0;t<alwaysnews.length;t++){
                    news+=alwaysnews[t].id+",";
                };
                hobby=hobby.substring(0,hobby.length-1);
                job=job.substring(0,job.length-1);

                $.ajax({
                    type: "post",
                    datatype: "json",
                    url: "http://42.62.66.198:9001/api/PuluUser/UpdateUser",
                    data:{"userId":id,"nick":nick,"city":city,"cover":cover,"sex":sex,"userAva":userAva,"sign":sign,"education":education,"visitedcity":cities},
                    success:function(data){
                        window.location.href="setpage.html";
                    }
                })
            }
        }

    })
});
document.onkeydown=function(event){
    var e = event || window.event || arguments.callee.caller.arguments[0];
    if(e && e.keyCode==13&&ctchoicepage.style.display=="block"){
        var word=$("#csearchinput").val();
        var allcitylist=document.getElementsByClassName("tc_inner");
        for(var i=0;i<allcitylist.length;i++){
            var listinner=allcitylist[i].innerHTML.match(/[\u4e00-\u9fa5]+/)[0];
            if(listinner===word){
                console.log("找到城市了"+word);
                var pinyinid=pinyin.getFullChars(word).toLowerCase();
                console.log("转成拼音ID："+pinyinid);
                location.href="#"+pinyinid;
                if(allmychoicecityclick===1){
                    console.log($(document).scrollTop()-104);
                    location.href="#";
                    $(document).scrollTop($(document).scrollTop()+104);
                }else{
                    location.href="#";
                    console.log($(document).scrollTop()-142);
                    $(document).scrollTop($(document).scrollTop());
                }
                break;
            }
        }
    }
}